package com.fxf.srb.core.controller.api;

import com.fxf.common.result.R;
import com.fxf.srb.core.pojo.entity.Lend;
import com.fxf.srb.core.service.ILendService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @author 饭小范
 * @version 1.0
 * @description: TODO
 * @date 2021/6/4 21:51
 */
@Api(tags = "标的")
@Slf4j
@RestController
@RequestMapping("/api/core/lend")
public class LendController {

    @Resource
    private ILendService iLendService;

    @ApiOperation("获取标的列表")
    @GetMapping("/list")
    private R list(){

        List<Lend> lends = iLendService.selectList();
        return R.ok().data("lends",lends);

    }

    @ApiOperation("获取标的详情")
    @PostMapping("/show/{id}")
    public R show(
            @ApiParam(value = "标的id",required = true)
            @PathVariable("id") Long id){

        Map<String, Object> lendDetail = iLendService.getLendDetail(id);
        return R.ok().data("lendDetail",lendDetail);
    }

    @ApiOperation("计算投资收益")
    @GetMapping("/getInterestCount/{invest}/{yearRate}/{totalmonth}/{returnMethod}")
    public R getInterestCount(
            @ApiParam(value = "投资金额", required = true)
            @PathVariable("invest") BigDecimal invest,

            @ApiParam(value = "年化收益", required = true)
            @PathVariable("yearRate")BigDecimal yearRate,

            @ApiParam(value = "期数", required = true)
            @PathVariable("totalmonth")Integer totalmonth,

            @ApiParam(value = "还款方式", required = true)
            @PathVariable("returnMethod")Integer returnMethod){

        BigDecimal interestCount = iLendService.getInterestCount(invest,yearRate,totalmonth,returnMethod);
        return R.ok().data("interestCount",interestCount);
    }

}
